package cn.com.longfuinfo.wx.controller.post;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.jfinal.aop.Duang;
import com.jfinal.plugin.activerecord.Record;

import cn.com.longfuinfo.wx.controller.BaseController;
import cn.com.longfuinfo.wx.dao.User;
import cn.com.longfuinfo.wx.dao.WxUser;
import cn.com.longfuinfo.wx.service.post.PostRestService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 产后恢复计划
 * @author yss
 */
public class PostRestController extends BaseController {
	protected Logger logger = Logger.getLogger(getClass());
	private PostRestService service = Duang.duang(PostRestService.class);
	
	/**
	 * 跳转产后恢复计划
	 */
	public void plan() {
		WxUser wxUser = getCurrentWxUser();
		int wxUserid=getCurrentWxUserid();
		Integer userid = wxUser.getInt("userid");
		User user = User.me().findById(userid);
		//查询商品列表
		//孕中可体检项目商品列表
		List<Record> list1 = service.findGoodsBytTitleCord("S00002",wxUserid);
		//产后满月可体验项目商品列表
		List<Record> list2 = service.findGoodsBytTitleCord("S00003",wxUserid);
		//产后恢复可体验项目商品列表
		List<Record> list3 = service.findGoodsBytTitleCord("S00004",wxUserid);
		List<Map<String,Object>> rtnList1 = new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> rtnList2 = new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> rtnList3 = new ArrayList<Map<String,Object>>();
		int i=0;
		for(Record record : list1){
			Map<String,Object> map = record.getColumns();
			rtnList1.add(map);
			if(record.get("orderState")==null||"".equals(record.get("orderState"))){
				i += 1;
			}
		}
		for(Record record : list2){
			Map<String,Object> map = record.getColumns();
			rtnList2.add(map);
			if(record.get("orderState")==null||"".equals(record.get("orderState"))){
				i += 1;
			}
		}
		for(Record record : list3){
			Map<String,Object> map = record.getColumns();
			rtnList3.add(map);
			if(record.get("orderState")==null||"".equals(record.get("orderState"))){
				i += 1;
			}
		}
		setAttr("user", user);
		setAttr("list1", rtnList1);
		setAttr("list2", rtnList2);
		setAttr("list3", rtnList3);
		setAttr("i", i);
		render("plan.jsp");
	}
}
